﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
using System.IO;
using Google.Protobuf;

public class Login : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        GameObject.Find("Login").GetComponent<Button>().onClick.AddListener(LoginClick);

    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void LoginClick()
    {
        var usernameInputField = GameObject.Find("Username").GetComponent<InputField>();
        var passwordInputField = GameObject.Find("Password").GetComponent<InputField>();

        string username = usernameInputField.text;
        string password = passwordInputField.text;

        //string sendBuffer = "{\"Login\": {\"Username\": \"" + username + "\", \"Password\": \"" + password + "\"}}";

        ClientLogin msgLogin = new ClientLogin()
        {
            Username = username,
            Password = password,
        };

        //MemoryStream rawOutput = new MemoryStream();
        //CodedOutputStream output = new CodedOutputStream(rawOutput);
        ////output.WriteRawVarint32((uint)len);
        //output.WriteMessage(msgLogin);
        //output.Flush();
        //byte[] sendBytes = rawOutput.ToArray();

        //byte[] sendBytes = msgLogin.ToByteArray();


        //ClientLogin msgLogin2 = new ClientLogin();
        //msgLogin2.MergeFrom(sendBytes);


        var tcpClient = GameObject.Find("Network").GetComponent<TcpClient>();
        tcpClient.SocketSend<ClientLogin>(msgLogin);

        //client.Connect(host, port);
    }

}


